#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int maxTurbulenceSize(vector<int>& arr) {
    int n = arr.size();
    vector<int> f(n, 1);
    auto g = f;
    int res = 1;
    for (int i = 1; i < n; i++)
    {
        if (arr[i - 1] > arr[i])
            f[i] = g[i - 1] + 1;
        else if (arr[i - 1] < arr[i])
            g[i] = f[i - 1] + 1;
        res = max(res, max(f[i], g[i]));
    }
    return res;
}